package mp

import (
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"ruikc.com/server/api/internal/logic/mp"
	"ruikc.com/server/api/internal/svc"
)

type WangFail struct {
	Errno   int    `json:"errno"`
	Message string `json:"message"`
}

type WangData struct {
	Url string `json:"url"`
	Alt string `json:"alt"`
}

type WangSuccess struct {
	Errno int      `json:"errno"`
	Data  WangData `json:"data"`
}

func FileWangHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		l := mp.NewFileWangLogic(r.Context(), svcCtx)
		resp, err := l.FileWang(r)
		if err != nil {
			result := WangFail{
				Errno:   1,
				Message: err.Error(),
			}
			httpx.OkJsonCtx(r.Context(), w, result)
		} else {
			result := WangSuccess{
				Errno: 0,
				Data: WangData{
					Url: resp.Url,
					Alt: resp.Name,
				},
			}
			httpx.OkJsonCtx(r.Context(), w, result)
		}
	}
}
